
$(function() {
    $('tbody tr td#clisk').click(function() {
        $this     = $(this).parent();
       
        $link     = $this.children('td:nth-child(1)').text();
        window.location.replace($link);
    });
    
    $('a#edit').click(function() {
      $('#navigation li:nth-child(3) a').click();
      $td     = $(this).parent();
      $tr     = $td.parent();
      
      $id         = $tr.children('td:nth-child(2)').text();
      $url        = $tr.children('td:nth-child(3)').text();
      $sortOrder  = $tr.children('td:nth-child(4)').text();
      $title      = $tr.children('td:nth-child(5)').text();
      $type       = $tr.children('td:nth-child(6)').text();
      
      //alert($id);
      $('#edit_item_id').val(jQuery.trim($id));
      $('#edit_title').val(jQuery.trim($title));
      $('#edit_type').val(jQuery.trim($type));
      if($type == 'inner') {
        $('#edit_link_select').val(jQuery.trim($url));
        
        $('#edit_link_select').show();
        $('#edit_link_select').attr("name","url");
        
        $('#edit_static_link').hide();
        $('#edit_static_link').attr("name","url_disabled");
        
      } else {
        $('#edit_static_link').val(jQuery.trim($url));
        
        $('#edit_static_link').show();
        $('#edit_static_link').attr("name","url");
        
        $('#edit_link_select').hide();
        $('#edit_link_select').attr("name","url_disabled");
        
        
      }
      $('#edit_sortOrder').val(jQuery.trim($sortOrder));
      
    })
    
    
    
    $('#cancel').click(function(){
        $('#navigation li:nth-child(1) a').click();
    })
    
    $('#insert').click(function(){
        $('#navigation li:nth-child(2) a').click();
    })
    
    $('#cancel2').click(function(){
        $('#navigation li:nth-child(1) a').click();
    })
    
    $('#type').change(function(){
      if($(this).val() == 'inner') {
        $('#link_select').show();
        $('#link_select').attr("name","url");
        
        $('#static_link').hide();
        $('#static_link').attr("name","url_disabled");
        
      } else {
        $('#static_link').show();
        $('#static_link').attr("name","url");
        
        $('#link_select').hide();
        $('#link_select').attr("name","url_disabled");
      }
    });
    
    $('#edit_type').change(function(){
      if($(this).val() == 'inner') {
        $('#edit_link_select').show();
        $('#edit_link_select').attr("name","url");
        
        $('#edit_static_link').hide();
        $('#edit_static_link').attr("name","url_disabled");
        
      } else {
        $('#edit_static_link').show();
        $('#edit_static_link').attr("name","url");
        
        $('#edit_link_select').hide();
        $('#edit_link_select').attr("name","url_disabled");
      }
    });
    
    
    
    
});